﻿using BLL.Dal;
using BLL.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class SysAdmin_User_Edit : System.Web.UI.Page
{
    public string user_id;
    public string user_name;
    public string user_pwd;
    public string user_fullname;
    public string user_sex;
    public string user_birthday;
    public string user_role;
    public string user_powers;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            bindData();
        }
    }

    /// <summary>
    /// 初始化数据绑定
    /// </summary>
    void bindData()
    {
        if (Request["user_key"] != null)
        {
            SysUserDAL userBus = new SysUserDAL();
            SysUser model = userBus.GetModel(new Guid(Request["user_key"]));
            if (model != null)
            {
                user_id = model.ID.ToString();
                user_name = model.userName;
                user_pwd = model.userPwd;
                user_fullname = model.fullName;
                user_sex = model.sex;
                if (model.birthday != null)
                {
                    user_birthday = Convert.ToDateTime(model.birthday).ToString("yyyy-MM-dd");
                }
                user_role = model.roleCode;
                UserPowerDAL uPowerBus = new UserPowerDAL();
                DataTable dtPower = uPowerBus.GetList(" userCode='" + model.userName + "'").Tables[0];
                if (dtPower.Rows.Count > 0)
                {
                    user_powers = "";

                    for (int i = 0; i < dtPower.Rows.Count; i++)
                    {
                        user_powers += "'" + dtPower.Rows[i]["powerCode"] + "'" + ",";
                    }

                    user_powers = "[" + user_powers.TrimEnd(',') + "]";

                }
            }
        }
    }
}